package com.mingmen.canting.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mingmen.canting.R;
import com.mingmen.canting.caigourenyuan.CaiGouWanAdapter;
import com.mingmen.canting.caigourenyuan.CaiGouWanRightAdapter;
import com.mingmen.canting.jingli.JingLiRuRightAdapter;
import com.mingmen.canting.model.CaiWanModel;
import com.mingmen.canting.model.JingLiRukuModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yjwfn on 17-9-23.
 */

public class JingLiRuKuAdapter extends RecyclerView.Adapter<JingLiRuKuAdapter.PhotoViewHolder> {


    Context context;
    List<JingLiRukuModel.DataBean> dataBeanList = new ArrayList<>();

    private OnItemClickListener mOnItemClickListener;

    public JingLiRuKuAdapter(Context context, List<JingLiRukuModel.DataBean> myList) {
        this.context = context;
        this.dataBeanList = myList;
    }

    public void setDataList(List<JingLiRukuModel.DataBean> myList) {
        this.dataBeanList = myList;

        notifyDataSetChanged();

    }

    @Override
    public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        return new PhotoViewHolder(inflater.inflate(R.layout.item_jingliruku, parent, false));
    }

    @Override
    public void onBindViewHolder(PhotoViewHolder holder, int position) {
//        holder.photoView.setImageResource(photos[position]);
        holder.text_name.setText(dataBeanList.get(position).getApplyId());
        List<JingLiRukuModel.DataBean.DetailsBean> second = new ArrayList<>();
        second = dataBeanList.get(position).getDetails();

        if (holder.chuShiRightAdapter == null) {
            holder.chuShiRightAdapter = new JingLiRuRightAdapter(context, second, position);
            LinearLayoutManager layoutManage = new LinearLayoutManager(context);
            holder.rv_item.setLayoutManager(layoutManage);
//            holder.rvItemItem.addItemDecoration(new GridSpacingItemDecoration(2, 20, false));
            holder.rv_item.setAdapter(holder.chuShiRightAdapter);
        } else {
            holder.chuShiRightAdapter.setPosition(position);
            holder.chuShiRightAdapter.notifyDataSetChanged();
        }

        if (dataBeanList.get(position).getStatus().equals("1")) {
            holder.status.setText("已完成");
        } else if (dataBeanList.get(position).getStatus().equals("0")) {
            holder.status.setText("未完成");
        }

        holder.applyId.setText(dataBeanList.get(position).getApplyId());
        holder.applyTime.setText(dataBeanList.get(position).getApplyTime());
        holder.total.setText(dataBeanList.get(position).getTotal() + "元");

     holder.chuShiRightAdapter.setOnitemClickLintener(new JingLiRuRightAdapter.OnitemClick() {

         @Override
         public void onItemClick(View view, int position, List<JingLiRukuModel.DataBean.DetailsBean> mList) {
             switch (view.getId()){
                 case R.id.layout_jump:
                     mOnItemClickListener.onItemClick(view, position, dataBeanList, mList);
                     break;
             }
         }
     });


    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    static final class PhotoViewHolder extends RecyclerView.ViewHolder {


        TextView text_name;
        RecyclerView rv_item;
        JingLiRuRightAdapter chuShiRightAdapter;
        TextView status;
        TextView applyId;
        TextView applyTime;
        TextView total;

        public PhotoViewHolder(View itemView) {
            super(itemView);

            text_name = itemView.findViewById(R.id.text_name);
            rv_item = itemView.findViewById(R.id.rv_item);
            status = itemView.findViewById(R.id.status);
            applyId = itemView.findViewById(R.id.applyId);
            applyTime = itemView.findViewById(R.id.applyTime);
            total = itemView.findViewById(R.id.price_totla);
        }
    }

    public interface OnItemClickListener {
        //        void onItemClickListener(int pos, DaishenheListAdapter.ViewName viewName, List<MyLiveList> myLiveList);
        void onItemClick(View view, int position, List<JingLiRukuModel.DataBean> mList, List<JingLiRukuModel.DataBean.DetailsBean> mNewList);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
